/**
 * Copyright 2025 Beijing Volcano Engine Technology Co., Ltd. All Rights Reserved.
 * SPDX-license-identifier: BSD-3-Clause
 */

import AvatarCard from '@/components/AvatarCard';
import AvatarMobileCard from '@/components/AvatarCard/AvatarMobileCard';
import Utils from '@/utils/utils';
import aigcConfig from '@/config';
import InvokeButton from '@/pages/MainPage/MainArea/Antechamber/InvokeButton';
import { useJoin } from '@/lib/useCommon';
import style from './index.module.less';
import utils from '@/utils/utils';
import { useSelector, useDispatch } from 'react-redux';
import { setTrainDuration } from '@/store/slices/room';

function Antechamber() {
  const [joining, dispatchJoin] = useJoin();
  const username = aigcConfig.BaseConfig.UserId;
  const roomId = aigcConfig.BaseConfig.RoomId;
  const room = useSelector((state: any) => state.room);
  const dispatch = useDispatch();

  const handleJoinRoom = () => {
    if( room.trainDuration <= 0 ) {
      const n = sessionStorage.getItem('TrainDuration');
      dispatch(setTrainDuration({ data: n || 1 }));
    }
    if (!joining) {
      dispatchJoin(
        {
          username,
          roomId,
          publishAudio: true,
        },
        false
      );
    }
  };

  return (
    <div className={style.wrapper}>
      <AvatarMobileCard className={`${style.avatar} ${style.mobile}`} />
      <InvokeButton onClick={handleJoinRoom} loading={joining} className={style['invoke-btn']} />
    </div>
  );
}

export default Antechamber;
